package com.yy.controller.mapper;

import com.github.pagehelper.Page;
import com.yy.dto.SetmealPageQueryDTO;
import com.yy.entity.Setmeal;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetmealMapper {




    /**
     * 根据categoryId查询当前分类下的套餐数量
     * @param categoryId
     * @return
     */
    @Select("select  count(*) from setmeal where category_id = #{categoryId}")
    Integer getByCategoryId(Long categoryId);

    /**
     * 分页条件查询套餐列表
     * @param setmealPageQueryDTO
     * @return
     */
    Page<Setmeal> pageList(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 根据id删除套餐
     * @param id
     */
    @Delete("delete from setmeal where id = #{id}")
    void delete(Long id);
    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Select("select * from setmeal where id = #{id}")
    Setmeal  setmealById(Long id);

    /**
     * 添加套餐
     * @param setmeal
     */
     void add(Setmeal setmeal);

    @Update("update setmeal  set name = #{name}," +
            "category_id = #{categoryId},price = #{price}," +
            "image = #{image},description = #{description}," +
            "status=#{status},update_time = #{updateTime}," +
            "update_user = #{updateUser} where id = #{id}")
    void update(Setmeal setmeal);

    /**
     * 通过categoryId查询在售套餐
     * @param categoryId
     * @return
     */
    @Select("select * from setmeal where category_id = #{categoryId} and status = 1")
    List<Setmeal> setmealListByCategoryIdandStatus(Long categoryId);
}
